﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FormKeyWordSearch.cs" company="">
//   
// </copyright>
// <summary>
//   The form key word search.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace NetworkSupervisor
{
    using System;

    using NetworkSupervisor.Helper;

    /// <summary>The form key word search.</summary>
    public partial class FormKeyWordSearch : DevExpress.XtraEditors.XtraForm
    {
        #region Fields

        /// <summary>The keyword.</summary>
        private string keyword;

        #endregion

        #region Constructors and Destructors

        /// <summary>Initializes a new instance of the <see cref="FormKeyWordSearch"/> class.</summary>
        public FormKeyWordSearch()
        {
            this.InitializeComponent();
        }

        #endregion

        #region Methods

        /// <summary>The form key word search_ load.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void FormKeyWordSearch_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
        }

        /// <summary>The form key word search_ shown.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void FormKeyWordSearch_Shown(object sender, EventArgs e)
        {
        }

        /// <summary>The btn search_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.keyword = this.txtKeyword.Text;

            System.Threading.ThreadPool.QueueUserWorkItem(this.callBack);
        }

        /// <summary>The call back.</summary>
        /// <param name="state">The state.</param>
        private void callBack(object state)
        {
            // this.keyword = UrlHelper.UrlEncode(this.keyword);
            string baiduUrl = string.Format("http://www.baidu.com/s?wd={0}", this.keyword);
            string sousouUrl = string.Format("http://www.soso.com/q?pid=s.idx&cid=s.idx.se&w={0}", this.keyword);
            string yahuUrl = string.Format("http://www.yahoo.cn/s?src=8003&vendor=100101&source=ycnhp_search_button&q={0}", this.keyword);
            string gugeUrl = string.Format("http://www.google.com.hk/#hl=zh-CN&newwindow=1&safe=strict&site=&source=hp&q={0}", this.keyword);
            string youdaoUrl = string.Format("http://www.youdao.com/search?q={0}", this.keyword);
            string bingUrl = string.Format("http://cn.bing.com/search?q={0}", UrlHelper.UrlEncode(this.keyword));
            string qihuUrl = string.Format("http://www.qihoo.com/wenda.php?kw={0}", this.keyword);
            string sougouUrl = string.Format("http://www.sogou.com/web?query={0}", this.keyword);
            string t360Url = string.Format("http://so.360.cn/s?q={0}", UrlHelper.UrlEncode(this.keyword));
            this.UIThread(
                () =>
                    {
                        this.webBrowserBaiDu.Navigate(baiduUrl);
                        this.webBrowserSouSou.Navigate(sousouUrl);
                        this.webBrowserYaHu.Navigate(yahuUrl);
                        this.webBrowserGuge.Navigate(gugeUrl);
                        this.wbQihu.Navigate(qihuUrl);
                        this.wbYoudao.Navigate(youdaoUrl);
                        this.wbBing.Navigate(bingUrl);
                        this.wbSouGou.Navigate(sougouUrl);
                        this.wb360.Navigate(t360Url);
                    });
        }

        #endregion
    }
}